#include "villes.h"
#include "comportementville.h"
#include "comportementallie.h"
#include "comportementennemi.h"
#include "comportementneutre.h"

Villes::Villes(QWidget *p): QLabel(p)
{
    proprietaire=0;
    defense=0;
    unites=0;
    compt = 0;
    villeOrJ1.load(":/Images/VilleJ1Or.png");
    villeOrJ2.load(":/Images/VilleJ2Or.png");
    villeFerJ1.load(":/Images/VilleJ1Fer.png");
    villeFerJ2.load(":/Images/VilleJ2Fer.png");
    villeOr.load(":/Images/VilleOr.png");
    villeFer.load(":/Images/VilleFer.png");
}


void Villes::setNom(QString i){
    nom=i;
}

QString Villes::getNom(){
    return nom;
}

int Villes::action(Villes* ville,int i)
{
        if(getProprietaire()== ville->getProprietaire())
        {
            comportement=new ComportementAllie();
        }else{
            if(ville->getProprietaire()==0){
                comportement= new ComportementNeutre;
            }else{
                comportement=new ComportementEnnemi();
            }
        }
        comportement->deplacement(this,ville,i);

    return ville->getProprietaire();

}

void Villes::setDefense(int i){
    defense=i;
}

void Villes::setProprietaire(int j)
{
    proprietaire=j;
    if(type==0){
        if (proprietaire==1)
            setPixmap(villeOrJ1);
        else
            setPixmap(villeOrJ2);}
    else {
        if (proprietaire==1)
            setPixmap(villeFerJ1);
        else
             setPixmap(villeFerJ2);}
}


int Villes::getProprietaire()
{
    return proprietaire;
}

void Villes::setUnites(int i)
{
    if(getUnites()+i>LIMIT_UNIT){

    }else{

        unites+=i;
        modifAff(unites);
    }
}

int Villes::getUnites()
{
    return unites;
}

int Villes::getDefense()
{
    return defense;
}

void Villes::addVoisin1(QString t){
    voisin.push_back(t);
    voisin2.push_back(t);
}

void Villes::addVoisin2(QString t){
    voisin2.push_back(t);
}

int Villes::getType()
{
    return type;
}

void Villes::setType(int i){
    type=i;
    if(type==0)
        setPixmap(villeOr);
    else
        setPixmap(villeFer);
}

void Villes::setAff(QLabel *a){
    aff=a;
}

void Villes::modifAff(int i){
    aff->setText(getNom()+"  "+QString::number(i));
}
